package day04;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Serverljc {

	public static void main(String[] args) throws Exception {
		System.out.println("----这里是服务器----");
		ServerSocket ss=new ServerSocket(8000);
		Socket s=ss.accept();
		BufferedReader br =new BufferedReader(new InputStreamReader(s.getInputStream()));
		PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
		Scanner sc=new Scanner(System.in);
		Thread duqu=new Thread(new Runnable() {

			@Override
			public void run() {
				while(true) {
					
					try {
						System.out.println("客户端说:"+br.readLine());
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				
			}
			
		});


		Thread shuchu =new Thread(new Runnable() {

			@Override
			public void run() {
				while(true) {
					//控制台输入。再发送信息到客户端
					String scin=sc.nextLine();
					pw.println(scin);
				}
				
			}
			
		});
		duqu.start();
		shuchu.start();


	}

}
